#include <iostream>
using namespace std;

// 交换函数

// 1、值传递
void mySwap1(int a, int b)
{
    int temp = a;
    a = b;
    b = temp;

    cout << "mySwap1中 a = " << a << endl;
    cout << "mySwap1中 b = " << b << endl;
}

// 2、地址传递
void mySwap2(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

// 3、引用传递
void mySwap3(int &a, int &b)
{
    int temp = a;
    a = b;
    b = temp;
}

int main()
{
    int a = 10;
    int b = 99;

    // 值传递，形参不会修饰实参
    mySwap1(a, b);
    cout << "mySwap1后：" << endl;
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;

    // 地址传递，形参会修饰实参
    mySwap2(&a, &b);
    cout << "mySwap2后：" << endl;
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;

    // 引用传递，形参会修饰实参
    mySwap3(a, b);
    cout << "mySwap3后：" << endl;
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;

    return 0;
}